const express = require("express")();
const mysql = require('mysql');
const port = 8081;

express.all("/*", function(req, res, next) {
    // 跨域处理
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1');
    res.header("Content-Type", "application/json;charset=utf-8");
    next(); // 执行下一个路由
})

var sql = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '123456',
  database : 'canyin',
  timezone : "08:00"
});
sql.connect();



express.get("/getSetList",(request,response)=>{
	sql.query(`SELECT * FROM setList`,(error,result)=>{
		if(error){
			console.log(error)
			response.end("error")
		}
		else{
			response.end(JSON.stringify(result))
		}
	})
})


express.listen(port)
console.log(`server is running at ${port}`)